package com.example.mynote.fragment;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.mynote.R;
import com.example.mynote.activity.LoginActivity;
import com.example.mynote.activity.ScActivity;
import com.example.mynote.activity.UseActivity2;
import com.example.mynote.base.BaseFragment;

public class PersonFragment extends BaseFragment {


    private ImageView txImage;
    private TextView userName;
    private LinearLayout syxzLayout;
    private LinearLayout fxLayout;
    private LinearLayout scLayout;
    private Button exitBtn;

    @Override
    protected int Layout() {
        return R.layout.fragment_person;
    }

    @Override
    protected void initView(View v) {

        txImage = (ImageView) v.findViewById(R.id.tx_image);
        userName = (TextView) v.findViewById(R.id.user_name);
        syxzLayout = (LinearLayout) v.findViewById(R.id.syxz_layout);
        fxLayout = (LinearLayout) v.findViewById(R.id.fx_layout);
        scLayout = (LinearLayout) v.findViewById(R.id.sc_layout);
        exitBtn = (Button) v.findViewById(R.id.exit_btn);
    }

    @Override
    protected void initData() {
        String name = mContext.getSharedPreferences("user", Context.MODE_PRIVATE).getString("name", "");
        userName.setText(name);
        syxzLayout.setOnClickListener(view -> intentTo(UseActivity2.class));
        fxLayout.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_TEXT, "这是一个分享");
            intent.setType("text/plain");
            startActivity(Intent.createChooser(intent, "请选择你要分析的途径"));
        });
        exitBtn.setOnClickListener(view -> {
            Intent intent = new Intent(mContext, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            getActivity().finish();
        });
        scLayout.setOnClickListener(view -> intentTo(ScActivity.class));
    }
}